//
//  ST_QuestionHomeViewController.swift
//  btvideo
//
//  Created by TT mini on 2022/6/22.
//  Copyright © 2022 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift
import DNSPageView

class ST_QuestionHomeViewController: ST_BTLightBarViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        if #available(iOS 11, *) {
        } else {
            automaticallyAdjustsScrollViewInsets = false
        }
        self.title_nav_btn.setTitleForAllStates("常见问题")
        view.backgroundColor = Color.init(hexString: "#F5F8FA")
        own_navigation_bar.backgroundColor = Color.init(hexString: "#F5F8FA")
        make_u_i()
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */
    
    private lazy var bottomBtn : UIButton = {
        let b = UIButton()
        b.backgroundColor = Color.init(hexString: "#FEC207")
        b.setTitleForAllStates("在线客服")
        b.setImageForAllStates(ST_ImageUtils.imageName("question_kefu_icon")!)
        b.cornerRadius = 20
        b.imageEdgeInsets = UIEdgeInsets(top: 0, left: -10, bottom: 0, right: 0)
        b.titleEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
        
        return b
    }()
    
    private lazy var pageViewManager : PageViewManager = {
        let style = PageStyle()
        style.isShowBottomLine = true
        style.titleViewHeight = 32
        style.titleMargin = 25
        style.bottomLineColor = Color.init(hexString: "#333333")!
        style.isTitleViewScrollEnabled = true
        style.titleViewBackgroundColor = .clear
        style.titleColor = Color.init(hexString: "#A7A7A7")!
        style.titleSelectedColor = Color.init(hexString: "#333333")!
        style.titleFont = .systemFont(ofSize: 14, weight: .medium)
        
        let titles = ["使用指南","充值/提现","认证","账号","守护","会员"]
        
        for i in 0..<titles.count {
            let controller = ST_QuestionBodyViewController()
            controller.currentPage = i + 1
            addChild(controller)
        }
        
        return PageViewManager(style: style, titles: titles, childViewControllers: children)
    }()

}

extension ST_QuestionHomeViewController {
    
    func make_u_i() {

        view.addSubview(bottomBtn)
        bottomBtn.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-BTSafeAreaBottom-10)
            make.left.equalToSuperview().offset(17)
            make.width.equalTo(ScreenWidth-34)
            make.height.equalTo(40)
        }
        
        view.addSubviews([pageViewManager.titleView,pageViewManager.contentView])
        pageViewManager.titleView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(navigationBarHeight + statusBarHeight)
            make.left.equalToSuperview()
            make.width.equalTo(ScreenWidth)
            make.height.equalTo(40)
        }
        
        if #available(iOS 11, *) {
            pageViewManager.contentView.collectionView.contentInsetAdjustmentBehavior = .never
        } else {
            automaticallyAdjustsScrollViewInsets = false
        }
        
        pageViewManager.contentView.snp.makeConstraints { make in
            make.top.equalTo(pageViewManager.titleView.snp.bottom)
            make.left.equalToSuperview()
            make.width.equalTo(ScreenWidth)
            make.bottom.equalTo(bottomBtn.snp.top)
        }
        
        bottomBtn.rx.controlEvent(.touchUpInside).subscribe(onNext: { [weak self] in
            
            guard let self = self else {return}
            //跳客服
            let vc = ST_PrivateChatViewController()
            
            vc.sessionID = DIALOGUE_ASSISTANT_SESSION_ID
            
            self.navigationController?.pushViewController(vc)
            
        }).disposed(by: rx.disposeBag)
    }
    
}

